package com.ydd.controller.admin;

import com.ydd.dto.ArticlePageDTO;
import com.ydd.entity.Page.YddArticlePageVO;
import com.ydd.entity.YddArticle;
import com.ydd.result.ArticlePage;
import com.ydd.result.Result;
import com.ydd.service.YddArticleService;
import com.ydd.vo.YddArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-05-02 14:48
 */

@Api(tags = "文章管理相关接口")
@Slf4j
@RestController
@RequestMapping("/ydd_article")
public class YddArticleController {
    @Autowired
    private YddArticleService yddArticleService;


    /**
     * 文章列表-分页
     * @param articlePageDTO
     * @return
     */
    @ApiOperation("文章列表-分页接口")
    @GetMapping("/list")
    public Result list(ArticlePageDTO articlePageDTO) {
        log.info("文章列表-分页:{}", articlePageDTO);
        ArticlePage articlePage = yddArticleService.list(articlePageDTO);
        return Result.success(articlePage);
    }

    /**
     * 文章删除
     * @param id
     * @return
     */
    @ApiOperation("文章删除接口")
    @GetMapping("/del")
    public Result del(String id){
        log.info("文章删除:{}",id);
        yddArticleService.del(id);
        return Result.success();
    }


    /**
     * 文章详情
     * @param id
     * @return
     */
    @ApiOperation("文章详情接口")
    @GetMapping("/rowInfo")
    public Result<YddArticle> rowInfo(String id){
        log.info("文章详情:{}",id);

        YddArticle yddArticle = yddArticleService.rowInfo(id);
        return Result.success(yddArticle);
    }

    /**
     * 文章修改
     * @param yddArticle
     * @return
     */
    @ApiOperation("文章修改接口")
    @GetMapping("/update")
    public Result<YddArticle> update(@RequestBody YddArticle yddArticle){
        log.info("文章修改");
        yddArticleService.update(yddArticle);
        return Result.success();
    }
}
